﻿/********************************************************************************************************************
* Author:	Christos Polydorou																						*
* Email:	std04237@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_entity_createattributevalue" that		*
*			creates the value for an ettribute of an entity.														*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_entity_createattributevalue]
	@categoryid bigint,
	@entityname nvarchar(50),
	@attributename nvarchar(50),
	@value nvarchar(50)
AS
	DECLARE @entityid bigint
	DECLARE @attributeid bigint

	SELECT @entityid = id											/* get the id of the entity */
	FROM Entities
	WHERE Entities.Category = @categoryid and Entities.Name = @entityname

	SELECT @attributeid = id										/* get the id of the attribute */
	FROM Attributes
	WHERE Attributes.name = @attributename and Attributes.category = @categoryid

	INSERT INTO [Entity-Attribute]
	VALUES(@entityid,@attributeid,@value)

RETURN 0